<?php
/**
* エラーチェッククラス
**/
require_once( '../system/Class_M_DAO.php' );
class Class_M_SHOP_RHIZOME  extends Class_M_DAO {
	//protected properties begin
	/**
	 *
	 * テーブル名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_table = "M_SHOP_RHIZOME";
	
	/**
	 *
	 * 主キー名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_pkey = "id";
	
	/**
	 *
	 * ソート順
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	 protected $_order = "shop_cd";
	 
	 protected $_cols     = array(
		"shop_cd"         => array(AOKI_VARTYPE_STR),
		"matrix_cd"       => array(AOKI_VARTYPE_INT),
		"now_quantity"    => array(AOKI_VARTYPE_INT),
		"last_quantity"   => array(AOKI_VARTYPE_INT),
		"diff_quantity"   => array(AOKI_VARTYPE_INT),
		"rate_quantity"   => array(AOKI_VARTYPE_INT),
	    "now_sales"       => array(AOKI_VARTYPE_INT),
		"last_sales"      => array(AOKI_VARTYPE_INT),
		"diff_sales"      => array(AOKI_VARTYPE_INT),
		"rate_sales"      => array(AOKI_VARTYPE_INT),
		"now_price"       => array(AOKI_VARTYPE_INT),
		"last_price"      => array(AOKI_VARTYPE_INT),
		"diff_price"      => array(AOKI_VARTYPE_INT),
		"rate_price"      => array(AOKI_VARTYPE_INT),
	 );
	
	 protected $_checks  = array(
		"shop_cd"         => array( "EXIST","NUM" ),
		"now_quantity"    => array( "NUM" ),
		"last_quantity"   => array( "NUM" ),
		"diff_quantity"   => array( "NUM" ),
		"rate_quantity"   => array( "NUM" ),
		"now_sales"       => array( "NUM" ),
		"last_sales"      => array( "NUM" ),
		"diff_sales"      => array( "NUM" ),
		"rate_sales"      => array( "NUM" ),
		"now_price"       => array( "NUM" ),
		"last_price"      => array( "NUM" ),
		"diff_price"      => array( "NUM" ),
		"rate_price"      => array( "NUM" )
	 );
	 
	 //maxlength 
	 protected $_maxlens  = array(
		"shop_cd "   =>  3 
	 );
	
	 public function search($where ,&$page = NULL ){
		$sql = "SELECT a.*,(select  user_name FROM M_LOGIN where id  = a.u_user) as m_user_name from {$this->_table}  a ";
		$sqlcnt = "SELECT COUNT(*) AS cnt FROM M_SHOP a ";
		return  parent::search($where ,$page ,$sql, $sqlcnt);
	}
	
	 public function searchcsv($where ,&$page = NULL ){	
	 	
		$sql = "SELECT a.*, p.shop_name as p_shop_name , b1.media_name as lnews1_name, b2.media_name as lnews2_name, b3.media_name as lnews3_name, b4.media_name as lnews4_name, b5.media_name as lnews5_name, " .
				"(select  user_name FROM M_LOGIN where id  = a.u_user) as m_user_name from {$this->_table}  a ".
				" LEFT JOIN M_MEDIA as b1 on a.lnews1  = b1.media_cd ".
				" LEFT JOIN M_MEDIA as b2 on a.lnews2  = b2.media_cd ".
				" LEFT JOIN M_MEDIA as b3 on a.lnews3  = b3.media_cd ".
				" LEFT JOIN M_MEDIA as b4 on a.lnews4  = b4.media_cd ".
				" LEFT JOIN M_MEDIA as b5 on a.lnews5  = b5.media_cd ".
				" LEFT JOIN M_SHOP  as p  on a.parent_shop_cd = p.shop_cd ";
				
		return  parent::search($where ,$page ,$sql);
	}
	
}

?>